<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<c:set var="ctx" value=" ${pageContext.request.contextPath}" />
<html>
<head>
<title>审计监察法务管理2</title>
<script type="text/javascript">
	var $grid;
	var grid;

	$(function() {
		$grid = $("#grid").datagrid($.extend({},datagridOption, {
			url : "${ctx}/fnd/auditProNop/dataGrid?search_EQ_type=${type}",
			//fitColumns : true,
		    columns : [ [  {
				field : 'ck',
				checkbox : true
			},{
				field : 'auditProDtl',
				title : '明细',
				width : 80,
				formatter:function(val,row){
					var iconCls = "btn btn-danger btn-sm ";
					if (row.detailsCnt > 0) {
						iconCls = "btn btn-success btn-sm ";
					}
					return '<button class="' + iconCls + '" onclick="go(\'' + '${ctx}/fnd/auditProNop/detail?id='
							+ row.id + '&businessKey=${param.businessKey}\')"><span class="glyphicon glyphicon-th-list "></span></button>';
				}
			}, {
				field : 'auditName',
				title : '审计监察法务项目',
				width : 380,
				sortable : true
			} , {
				field : 'attachmentMaster',
				title : '附件',
				sortable : true,
				formatter : function(value, row, index) {
					if(row.attachCnt==0){
						return "<button id=\"attach\" type=\"button\" class=\"btn btn-default\" onclick=\"fn_attachClick('"+value.id+"',"+row.detailsApprCnt+")\"><span class=\"glyphicon glyphicon-pencil\"></span> 附件</button>";
					}else{
						return "<button id=\"attach\" type=\"button\" class=\"btn btn-primary\" onclick=\"fn_attachClick('"+value.id+"',"+row.detailsApprCnt+")\"><span class=\"glyphicon glyphicon-pencil\"></span> 附件</button>";
					}
				}
			}] ],
		}));
		
		$grid.datagrid('enableFilter', [ buildDGFilterYesOrNoFieldOptions($grid, 'enable') ]);
	     $("#add").click(function() {
			$("#fm").form("clear");
			$('#fm').form('load', {
				enable : 1,
				type:${type}
			});
			$("#dlg").dialog("open").dialog("setTitle", "新增审计监察法务项目");
		});
		$("#edit").click(function() {
			var rowData = $grid.datagrid("getSelected");
			if (!rowData) {
				showInfo("您未选中行，无法编辑");
			} else {
				fn_edit(rowData);
			}
		});
		
		//excel导入
		$("#excelImport").click(function() {
			$.easyui.importor.showImportor({
				importNo : "auditProNop",
				onExportSuccess : function(file, data) {
					$grid.datagrid('load');
				}
			});
		});
		
		$("#delete").click(function() {
			//method1('grid');
			
			multiDeleteDataGrid($grid, "${ctx}/fnd/auditProNop/multiDelete");
		});
		$("#search").click(function() {
			$grid.datagrid('load', $("#tt").form("getData"));
		});
		$("#excelExport").click(function() {
			var url = "${ctx}/fnd/auditProNop/excelExport?" + $.param($grid.datagrid('options').queryParams);
			if ($grid.datagrid("options").filterRules) {
				url += "&filterRules=" + JSON.stringify($grid.datagrid("options").filterRules);
			}
			window.parent.location.href = url;
		});
		 
	});
	 
	function fn_edit(rowData) {
		if (rowData.detailsApprCnt == 0) {
			$("#dlg-btn").show();
			$("#dlg").dialog("open").dialog("setTitle", "编辑审计监察法务项目");
			$("#fm").form("clear");
			$("#fm").form("load", rowData);
		} else {
			$("#dlg-btn").hide();
			$("#dlg").dialog("open").dialog("setTitle", "查看审计监察法务项目");
			$("#fm").form("clear");
			$("#fm").form("load", rowData);
		}
		
	}
 
	//打印功能的实现
	<shiro:hasPermission name="auditProNop:print">
	   function fun_print()
	   {
		   printDataGrid($grid, "${ctx}/fnd/auditProNop/print?ids=");
	   }
	   function printDataGrid($grid, printUrl, operName) {
			var rows = $grid.datagrid('getChecked');
			var ids = "";
			if (rows) {
				$.each(rows, function(index, value) {
					ids += (value.id + ",")
				});
				if (ids == "") {
					$.messager.alert("操作提醒", "请先勾选需要打印的记录", "warning");
				} else {
					$.messager.confirm("您确定要打印勾选的" + rows.length + "条记录吗？", function(c) {
						if (c) {
							window.open(printUrl+ids, "_blank");//重新打开 
						}
					});
				}
			} else {
				$.messager.alert("操作提醒", "请先勾选需要打印的记录", "warning");
			}
		}
	   </shiro:hasPermission>
	   
	 //-----------------------------附件-----------------------------------------------//		
		function fn_attachClick(id,detailsApprCnt){
		  
			grid&&grid.datagrid('loadData',{total:0,rows:[]});
			grid = $("#grid_attach").datagrid({
				title : "附件",
				fitColumns : true,
				method : "get",
				singleSelect : true,
				pagination : true,
				url : "${ctx}/basic/attachment/dataGrid/"+id
			});
			
			if(detailsApprCnt==0){
		 
				$("#dlg_attach").dialog("open").dialog("setTitle", "编辑附件");
				$('#uploader').show();
				 uploader&&uploader.destroy();
				    initWebuploader(id);
			}else{
				$("#dlg_attach").dialog("open").dialog("setTitle", "查看附件");
				$('#uploader').hide();
			}
		}
		
		function fn_attach_formatter(value, row, index) {
			var rowData = $grid.datagrid('getSelected');
			var button="";
			if(rowData.detailsApprCnt>0){
				button=fmt_attachView(value, row, index);
			}else{
				button=fmt_attach(value, row, index);
			}
			 
			 return button;
		}
	
		
		
	    var idTmr;
		function  getExplorer() {
			var explorer = window.navigator.userAgent ;
			//ie 
			if (explorer.indexOf("MSIE") >= 0) {
				return 'ie';
			}
			//firefox 
			else if (explorer.indexOf("Firefox") >= 0) {
				return 'Firefox';
			}
			//Chrome
			else if(explorer.indexOf("Chrome") >= 0){
				return 'Chrome';
			}
			//Opera
			else if(explorer.indexOf("Opera") >= 0){
				return 'Opera';
			}
			//Safari
			else if(explorer.indexOf("Safari") >= 0){
				return 'Safari';
			}
		}
        function method1(tableid) {//整个表格拷贝到EXCEL中
			if(getExplorer()=='ie')
			{
				var curTbl = document.getElementById(tableid);
				var oXL = new ActiveXObject("Excel.Application");
				
				//创建AX对象excel 
				var oWB = oXL.Workbooks.Add();
				//获取workbook对象 
				var xlsheet = oWB.Worksheets(1);
				//激活当前sheet 
				var sel = document.body.createTextRange();
				sel.moveToElementText(curTbl);
				//把表格中的内容移到TextRange中 
				sel.select();
				//全选TextRange中内容 
				sel.execCommand("Copy");
				//复制TextRange中内容  
				xlsheet.Paste();
				//粘贴到活动的EXCEL中       
				oXL.Visible = true;
				//设置excel可见属性

				try {
					var fname = oXL.Application.GetSaveAsFilename("Excel.xls", "Excel Spreadsheets (*.xls), *.xls");
				} catch (e) {
					print("Nested catch caught " + e);
				} finally {
					oWB.SaveAs(fname);

					oWB.Close(savechanges = false);
					//xls.visible = false;
					oXL.Quit();
					oXL = null;
					//结束excel进程，退出完成
					//window.setInterval("Cleanup();",1);
					idTmr = window.setInterval("Cleanup();", 1);

				}
				
			}
			else
			{
				tableToExcel(tableid)
			}
        }
        function Cleanup() {
            window.clearInterval(idTmr);
            CollectGarbage();
        }
		var tableToExcel = (function() {
			  var uri = 'data:application/vnd.ms-excel;base64,',
			  template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>',
				base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) },
				format = function(s, c) {
					return s.replace(/{(\w+)}/g,
					function(m, p) { return c[p]; }) }
				return function(table, name) {
				if (!table.nodeType) table = document.getElementById(table)
				var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
				window.location.href = uri + base64(format(template, ctx))
			  }
			})()
			
	 

</script>
</head>

<body>
	<div data-options="region:'center',fit:true,border:false">
		<table id="grid">
		</table>
	</div>
	<div id="tt" class="row">
		 
		<div class="col-md-8">
			<shiro:hasPermission name="auditProNop:update">
				<button id="add" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-plus"></span> 新增
				</button>
				<button id="edit" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-pencil"></span> 编辑
				</button>
			</shiro:hasPermission>
			<shiro:hasPermission name="auditProNop:delete">
				<button id="delete" type="button" class="btn btn-danger">
					<span class="glyphicon glyphicon-minus"></span> 删除
				</button>
			</shiro:hasPermission>
			<shiro:hasPermission name="auditProNop:export">
				<button id="excelExport" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-open"></span> Excel导出
				</button>
			</shiro:hasPermission>

			<%-- <shiro:hasPermission name="auditProNop:update">
				<button id="excelImport" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-save"></span> Excel导入
				</button>
			</shiro:hasPermission> --%>
			 
		</div>
	</div>
	<shiro:hasPermission name="auditProNop:update">
		<div id="dlg" class="easyui-dialog" style="width: 720px; height: 165px; padding: 10px 20px"
			data-options="resizable:true,modal:true, buttons:'#dlg-btn',closed:true">
			<form id="fm" method="post">
		<input type="hidden" name="id" /> 
		<input type="hidden" name="type" />     
				<table id="tbl">
					<tr>
						<td><label>审计监察法务名称:</label></td>
						<td colspan="3"><input name="auditName" class="easyui-validatebox" data-options="width:470,required: true"></td>
					</tr>
					 
					 
				</table>
			</form>
			<div id="dlg-btn">
				<button id="add" type="button" class="btn btn-primary" onclick="formSave('#fm', '#grid', '#dlg', '${ctx}/fnd/auditProNop/update');">
					<span class="glyphicon glyphicon-ok"></span> 保存
				</button>
				<button id="edit" type="button" class="btn btn-primary" onclick="$('#dlg').dialog('close');">
					<span class="glyphicon glyphicon-remove"></span> 取消
				</button>
			</div>
		</div>

	
	
		<div id="dlg_attach" class="easyui-dialog"
			style=" padding: 10px 20px"
			data-options="resizable:true,modal:true,closed:true,fit:true">
			<div  class="easyui-layout" data-options="fit:true">   
				<div data-options="region:'center',border:false">
					<table id="grid_attach" data-options="fit:true">
						<thead>
							<tr>
								<th field="id" hidden="true"></th>
								<th field="fileName" width="160">文件名称</th>
								<th field="fileSize" width="60">大小</th>
								<th field="uploadTime" width="60">上传时间</th>
								<th field="operate" width="60" data-options="formatter:fn_attach_formatter"  >操作</th>
							</tr>
						</thead>
					</table>
				</div>
				<div data-options="region:'south'" style="height:150px">
					<div id="uploader" class="wu-example">
					    <div class="btns">
					        <div id="picker">选择文件</div>
					    </div>
					     <!--用来存放文件信息-->
					    <div id="thelist" class="uploader-list"></div>
					</div>
				</div>
			</div>
		</div>
		
	</shiro:hasPermission>
</body>
</html>
